<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="button" value="按钮" id="btn">
    <script>
        var btn = document.getElementById("btn");
        // 调用函数
        addEvent(btn,"click",function(){
            alert(123);
        });
        // 自定义注册函数
        function addEvent(ele,type,fun){
            if(ele.addEventListener){
                ele.addEventListener(type,fun);
            }else if(ele.attachEvent){
                ele.attachEvent("on"+type,fun);
            }
        }
    </script>
</body>
</html>